home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / m68k / fbug68k.arc / PRINTPO.RTC < prev    next >
Text File  |  1989-09-29  |  3KB  |  144 lines

  1. #include"userdef.h"
  2.  
  3. int print(pfmt)
  4. char *pfmt;
  5. {
  6.   return(format(&pfmt));    /* pass ptr to fmt ptr */
  7. }
  8.  
  9. int format(pfmt)
  10. char **pfmt;        /* pointer to pointer to format string */
  11. {
  12. register char pch;
  13. register char *pformat;        /* pointer to format string */
  14. register char *pargument;        /* pointer to arg's for fmt string */
  15. register int pvalue,pi,pj, pk;
  16. int pmaxwidth,pmaxpoints;
  17. char pstr[MAXLINE];
  18. unsigned ptemp;
  19.  
  20.     pformat = *pfmt++;    /* set "format" to the format string */
  21.     pargument = (char *) pfmt;
  22.  
  23.     while (pch = *pformat++)
  24.       {
  25.           if (pch == '%')
  26.             {
  27.                 pch = *pformat++;
  28.             pi = 1;
  29.             pmaxwidth = 0;
  30.             pmaxpoints = 0;
  31.                 while ((pch >= '0') && (pch <= '9'))
  32.             {
  33.                 pmaxwidth = (pch - '0') * pi + pmaxwidth;
  34.                 pi = pi * 10;
  35.                 pch = *pformat++; 
  36.             }
  37.                 if (pch == '.')
  38.             {
  39.                 pch = *pformat++;
  40.                 while ((pch >= '0') && (pch <= '9'))
  41.                 {
  42.                     pmaxpoints = (pch - '0') * pi + pmaxpoints;
  43.                     pi = pi * 10;
  44.                     pch = *pformat++;
  45.                 }
  46.             }
  47.             *pformat--;
  48.             pch = *pformat++;
  49.             switch (pch)
  50.                   {
  51.                   case 'd':
  52.                   case 'u':
  53.             case 'x':
  54.             case 'X':
  55.                        pvalue = *(int *)pargument;
  56.                     pargument += 4;
  57.                 if (pch == 'd' && pvalue < 0)
  58.                   {
  59.                       putch(TERMINAL,'-');
  60.                         pvalue = -pvalue;
  61.                   }
  62.                                 if (pch == 'X' && pvalue < 0)
  63.                                 {
  64.                                         pvalue = -pvalue;
  65.                                 }
  66.                 if ((pch == 'd') || (pch == 'u'))
  67.                     pk = 10;
  68.                 else
  69.                     pk = 16;
  70.                 pi = 0;
  71.                 ptemp = pvalue;
  72.                 do
  73.                 {
  74.                     pstr[pi] = (ptemp % pk) + '0';
  75.                     if (pstr[pi] > '9')
  76.                         pstr[pi] = pstr[pi] - ':' + 'A';
  77.                     pi++;
  78.                 }
  79.                 while ((ptemp = ptemp / pk) > 0);
  80.                 pstr[pi] = ENDSTR;
  81.                 pj = --pi;
  82.                 for (pk = 0; pk < pj; pk++)
  83.                 {
  84.                     pch = pstr[pk];
  85.                     pstr[pk] = pstr[pj];
  86.                     pstr[pj--] = pch;
  87.                 }
  88.                 if(pmaxwidth != 0)
  89.                 {
  90.                                     pmaxwidth = pmaxwidth - pi - 1;
  91.                                        while (pmaxwidth > 0)
  92.                                        {
  93.                                                putch(TERMINAL,'0');
  94.                                                pmaxwidth--;
  95.                                        }
  96.                     pi = 0;
  97.                                        while (pmaxwidth < 0)
  98.                                      {
  99.                                                pmaxwidth++;
  100.                         pi++;
  101.                                        }
  102.                 }
  103.                 else
  104.                     pi = 0;
  105.                 for (pi=0;pstr[pi] != ENDSTR;pi++)
  106.                     putch(TERMINAL,pstr[pi]);
  107.                 break;
  108.  
  109.                   case 'c':
  110.                     pvalue = *(int *)pargument;
  111.                     pargument += 4;
  112.                 putch(TERMINAL,pvalue);
  113.                 break;
  114.     
  115.                   default:
  116.                 pformat--;  /* need to back up if unrecognized */
  117.                 putch(TERMINAL,'%');
  118.  
  119.                   }        /* switch c */
  120.  
  121.             }
  122.           else if (pch == '\n')
  123.             {
  124.                 putch(TERMINAL,CR);    /* cr */
  125.                 putch(TERMINAL,LF);    /* lf */
  126.             }
  127.           else
  128.                 putch(TERMINAL,pch); 
  129.     } 
  130.   }
  131.  
  132. /* ************************************************************ */
  133.  
  134. putch(addr,data)
  135. int addr,data;
  136. {
  137.     while ((get8(addr + SRX) & 4) == 0)
  138.         ;
  139.     put8(addr + TBX,data);
  140. }
  141.  
  142. /* ************************************************************ */
  143.  
  144.